<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
 <div class="Wrapper">
        <div>
           <div id="pageInTab" class="pageInTab">
		   <div tabid="tabA" title="基本信息" lselected="true">
		<form id="fnc_prj_bsc_info_form" >
             <div class="fieldset1 tabel_col clearFix">
              <div class="fieldBox col_50">
                    <div class="label">项目名称</div>
                <div class="field">
                  <span id="fncprjnm" name="fncprjnm">&nbsp;${focvo.fncPrjNm}</span>
                </div>

             </div>
              <div class="fieldBox col_50">
                    <div class="label">还款期次</div>
                <div class="field">
                  <span id="payPd" name="payPd">&nbsp;${focvo.payPd}</span>
                </div>

             </div>
             <div class="fieldBox col_50">
                <div class="label">金融机构</div>
                <div class="field">
                    <span id="fncinsNM" name="fncinsNM" class="insAccNo"  accId="180628249000661" >&nbsp;${focvo.fncInsNm}</span>
                </div>

             </div>
                             
             <div class="fieldBox col_50">
                    <div class="label">融资方案</div>
                <div class="field">
                   <span id="fncscmNM" name="fncscmNM">&nbsp;${focvo.fncScmNm}</span>
                </div>

             </div>
               <div class="fieldBox col_50">
                    <div class="label">归集日期</div>
                <div class="field">
                   <span id="gthrDt" name="gthrDt">&nbsp;${focvo.gthrDt}</span>
                </div>
               
             </div>
                      <div class="fieldBox col_50">
                    <div class="label">还款日期</div>
                <div class="field">
                   <span id="payDt" name="payDt">&nbsp;${focvo.payDt}</span>
                </div>

             </div>
              <div class="fieldBox col_50">
                    <div class="label">超额抵押</div>
                <div class="field">
                   <span id="paidUpAmt" name="paidUpAmt">&nbsp;${focvo.paidUpAmt/100}</span>
                </div>
               
             </div>
                      <div class="fieldBox col_50">
                    <div class="label">到账超额抵押</div>
                <div class="field">
                   <span id="transAm1" name="transAm1">&nbsp;${focvo.transAm/100}</span>
                </div>

             </div>
             
             <!-- 新增字段“历史退回金额”、“历史不可退回金额” -->
             <div class="fieldBox col_50">
				<div class="label">历史退回金额</div>
                <div class="field">
                	<input id="hisTransAm" name="hisTransAm" type="hidden" class="ui-textbox" value="${focvo.hisTransAm/100}" />
                	<span id="hisTransAm_1" name="hisTransAm_1">&nbsp;${focvo.hisTransAm/100}</span>
                </div>
             </div> 
             <div class="fieldBox col_50">
				<div class="label">历史不可退回金额</div>
                <div class="field">
                	<span id="hisTransAccNoReturn" name="hisTransAccNoReturn">&nbsp;${focvo.hisTransAccNoReturn/100}</span>
                </div>
             </div> 
             
         
              <div class="fieldBox col_50">
                    <div class="label">到账日期</div>
                <div class="field">
                    <input name="transTm" id="transTm" type="text"  class="ui-datepicker" value="${focvo.transTm}" validate="{required:true}">
                </div>
                <div style="display: none">
                </div>
             </div>       
                <div class="fieldBox col_50">
                    <div class="label">退回金额</div>
                <div class="field">
                 <input name="prjid" id="prjid" type="hidden" class="ui-textbox" value="${focvo.prjId}"> 
                 <input name="payId" id="payId" type="hidden" class="ui-textbox" value="${focvo.payId}"> 
                 <input name="payPd1" id="payPd1" type="hidden" class="ui-textbox" value="${focvo.payPd}"> 
                 <input name="transAm" id="transAm" type="text" class="ui-textbox" value="" validate="{number:true,required:true}" onchange="setSurplus()">
                </div>
                <div style="display: none">
                </div>
             </div> 
              <div class="fieldBox col_50">
                    <div class="label">不可退回金额</div>
                <div class="field">
                 <input name="transAccNoReturn" id="transAccNoReturn" type="text" class="ui-textbox" value="" validate="{number:true,required:true}" >
                </div>
             </div> 
    
             
               <div class="fieldBox col_50">
                    <div class="label">我司收款账号</div>
                <div class="field">
                   
                    <input name="accNo" id="accNo" type="text"   class="ui-textbox"  readonly="readonly" value=""  validate="{required:true}" >
                    <input name="transAcc" id="transAcc" type="hidden" class="ui-textbox" value="${focvo.transAcc}" >
                 <span id="chooseCst" class="sq-button sq-button-round"  onclick="choosePage()">选择我司收款账号</span>
                </div>
                <div style="display: none">
                </div>
             </div>  
              <div class="fieldBox col_50">
                    <div class="label">我司收款银行</div>
	                <div class="field">
	                    <input name="transBank" id="transBank" type="text" class="ui-textbox" readonly="readonly" value="${focvo.transBank}" validate="{required:true}" >
	                </div>
             </div>    
              <div class="fieldBox col_50">
                    <div class="label">我司收款账户</div>
	                <div class="field">
	                	<span id="accNm"></span>
	                </div>
             </div>
              <div class="fieldBox col_50">
                    <div class="label">机构付款账号</div>
                <div class="field">
                    <input  id=insAccNum  name="insAccNum"  type="text"  class="ui-textbox"   readonly="readonly"   validate="{required:true}" >
                    <input  id="insAccId"  name="insAccId"   type="hidden" class="ui-textbox" value="${focvo.payAccountId}" >
                    <span class="sq-button sq-button-round"  onclick="selectInsAcc();">选择机构付款账号</span>
                </div>
             </div>  
            <div class="fieldBox col_50">
                    <div class="label">机构付款账户名称</div>
	                <div class="field">
	                	<span id="insAccNm"></span>
	                </div>
             </div>
               <div class="fieldBox col_50">
                    <div class="label">机构付款开户行</div>
	                <div class="field">
	                	<span id="insBanAccNm"></span>
	                </div>
             </div>
              <div class="fieldBox col_50">
                    <div class="label">机构付款开户行号</div>
	                <div class="field">
	                	<span id="insBanAccNum"></span>
	                </div>
             </div>
             
			<!-- 当前盈余=退回金额+历史退回金额-已付超额抵押 -->  
			<div class="fieldBox col_50">
				<div class="label"><font color="red"><b>当前盈余</b></font></div>
                <div class="field">
                    <input id=surplus name="surplus" type="text" class="ui-textbox" readonly="readonly" validate="{required:true}" />
                </div>
			</div>
			 	
            </div>
   			<div class="btnsBox">
               <span id="saveBtn" class="sq-button sq-button-round" onclick="save()">发起流程</span>
            </div>
 

	         
         
        </form>
        </div>
             
        </div>
        </div>
    </div>
    
	<script type="text/javascript">
	  var pageInApp={
	    		flag:true
	    };
	  var id ='${id}';
	  var selectOrgCd = "";
	   var searchOrgTree = null;
	  var firstNode = null;
	  var textName='${orgTextName}';//节点名称
	  var orgData = null;
		var id ="";//初始值
		var detailFlag = '${detailFlag}';
		var isFlow = '${isFlow}';
$(function () {
	initData();
	//initPayList();
	
	
		
	//机构帐号	，显示详情
    $("#insAccNum").hover(function (obj) {
    	if($("#insAccId").val()) {
    		//根据id，获取机构帐号详细信息
        	var _this = $(this);
        	 $.ajax({
       		 		type: 'get',
       		 		dataType:'json',
       		 		url: '<%=path%>/rfbase/fribaseinfo/getAccById.do?id='+$("#insAccId").val(),
   			    		success:function(msg){
   			    			 if(msg.success == 1){
   			    				console.log(msg);
   			    				_this.after(setInsAccNoHtml(msg.data));
   			    			 }
   			    		}
   			    });
    	}
	},
    function() {
		setTimeout('$(".accNoTable").remove()',1000);
    }); 
	
	function setInsAccNoHtml(data) {
		var html ='<table class="accNoTable"  style="width:400px;position:absolute;z-index:100;left:0px;top:20px;background-color:#FFF; color:#000;" border="1" bordercolor="#C0C0C0"  >';
			html +='<tr><td bgcolor="#e5fef4">账户用途</td><td bgcolor="#FFFFFF">'+data.accTypCdNm+'</td><td bgcolor="#e5fef4">类型</td><td bgcolor="#FFFFFF">'+data.pubVerPriCdNm+'</td></tr>';
			html +='<tr><td bgcolor="#e5fef4">开户行号</td><td bgcolor="#FFFFFF">'+data.banAccNum+'</td><td bgcolor="#e5fef4">开户行</td><td bgcolor="#FFFFFF">'+data.banAccNm+'</td></tr>';
			html +='<tr><td bgcolor="#e5fef4">户名</td><td bgcolor="#FFFFFF">'+data.accNm+'</td><td bgcolor="#e5fef4">帐号</td><td bgcolor="#FFFFFF">'+data.accNum	+'</td></tr>';
			html +='<tr><td bgcolor="#e5fef4">备注</td><td bgcolor="#FFFFFF">'+data.rem+'</td><td bgcolor="#e5fef4"></td><td bgcolor="#FFFFFF"></td></tr>';
			html +='</table>';
		
		return html;
	}
	
	
	//我司帐号	，显示详情
    $("#accNo").hover(function (obj) {
    	if($("#transAcc").val()) {
    		//根据id，获取我司帐号详细信息
        	var _this = $(this);
        	 $.ajax({
       		 		type: 'get',
       		 		dataType:'json',
       		 		url: '<%=path%>/system/sysBkAccInfo/getById.do?id='+$("#transAcc").val(),
   			    		success:function(msg){
   			    			 if(msg.success == 1){
   			    				console.log(msg);
   			    				_this.after(setMyAccNoHtml(msg.data));
   			    			 }
   			    		}
   			    });
    	}
	},
    function() {
		setTimeout('$(".accNoTable").remove()',1000);
    }); 
	
	function setMyAccNoHtml(data) {
		var html ='<table class="accNoTable"  style="width:400px;position:absolute;z-index:100;left:0px;top:20px; background-color:#FFF; color:#000;" border="1" bordercolor="#C0C0C0"  >';
			html +='<tr><td bgcolor="#e5fef4">类型</td><td bgcolor="#FFFFFF">'+data.accTypNm+'</td><td bgcolor="#e5fef4"></td><td bgcolor="#FFFFFF"></td></tr>';
			html +='<tr><td bgcolor="#e5fef4">开户行号</td><td bgcolor="#FFFFFF">'+data.sysBkInfoVO.bkNo+'</td><td bgcolor="#e5fef4">开户行</td><td bgcolor="#FFFFFF">'+data.bkNm+'</td></tr>';
			html +='<tr><td bgcolor="#e5fef4">户名</td><td bgcolor="#FFFFFF">'+data.accNm	+'</td><td bgcolor="#e5fef4">帐号</td><td bgcolor="#FFFFFF">'+data.accNo	+'</td></tr>';
			html +='<tr><td bgcolor="#e5fef4">备注</td><td bgcolor="#FFFFFF">'+data.accRem+'</td><td bgcolor="#e5fef4"></td><td bgcolor="#FFFFFF"></td></tr>';
			html +='</table>';
		
		return html;
	}
	
	
	
	
	
	
	
var gthrDt="${focvo.gthrDt}";
if(gthrDt!=""){
	$("#gthrDt").text(DateUtils.formatDate(new Date(gthrDt), DateUtils.YYYY_MM_DD));	
}
var payDt="${focvo.payDt}";
if(payDt!=""){
	$("#payDt").text(DateUtils.formatDate(new Date(payDt), DateUtils.YYYY_MM_DD));	
}
$("#paidUpAmt").text(new Number("${focvo.paidUpAmt/100}"))
$("#transAm1").text(new Number("${focvo.transAm/100}"))
$("#transAm").text(new Number("${focvo.transAm/100}"))
});
	//初始化数据
	function initData(){
		//	initOrgTree();

		
	//	initcombobox();
		
		 initTab();
			$("#fnc_prj_bsc_info_form").ligerForm({
			    validate: true
			});
			 var ligerForm = liger.get("fnc_prj_bsc_info_form");
		 $("#fnc_prj_bsc_info_form").check_ligerFormEditor();
		
		/*  // 设置业务种类默认为禁用
		    var slt=liger.get("loanTypCd");
            slt.setDisabled();
 */
	
		
		
	
		
	}
	var pageInTab = null;
	  var loadedTabs=[]

	
	  

	  
   
	
	//初始化Tab
    function initTab(){
    	 pageInTab = $("#pageInTab").ligerTab({
             height: 'auto',
             contextmenu: false,
             minIframeHeight: GET_minIframeHeight(),
             onBeforeSelectTabItem: function (tabid) {
             	var id = $("#prjid").val();
             		//alert("id="+id);
             	 if(tabid!="tabA"){
 	             	if(id==null||id==''){
 	                	top.$.ligerDialog.SQalert({content:"请先保存项目基本信息", SQ_type: "warning"});
 	                	return false;
 	                } 
             	} 
             },
             onAfterSelectTabItem: function(tabid) {
              //   if (loadedTabs.indexOf(tabid)<0) {
                 	var id = $("#prjid").val();
                 	//alert("id="+id);
                 	 if(tabid!="tabA"){
 	                	if(id==null||id==''){
 	                		 top.$.ligerDialog.SQalert({content: LogUtils.LOG_PRJ__PRD_SELECT_BEFORE, SQ_type: "warning"});
 	                         return false; //验证不通过，不执行以下代码
 	                	}
                 	} 
                     loadedTabs.push(tabid);

            //     };
                 SetIframe_height();
             }
         });

         $.extend(true, pageInApp, {
             pageInTab: pageInTab
         });
    };
	//保存项目基础信息
	function save(){
        var ligerForm = liger.get("fnc_prj_bsc_info_form");
        if (!ligerForm.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
                   var transAm1 =new Number("${focvo.transAm/100}");
                   var paidUpAmt=new Number("${focvo.paidUpAmt/100}");
                   var transAm =new Number($("#transAm").val());
                   //alert(paidUpAmt-transAm1-transAm);
                  /*  if(paidUpAmt<transAm1+transAm){
                	   top.$.ligerDialog.SQalert({content:"到账金额不能大于剩余超额抵押："+(paidUpAmt-transAm1),SQ_type: "warning"});
                       return false;   
                   } */
                   
	    				  var data = ligerForm.getData();
	    				  console.log(data);
	    				  /* return ; */
	    			       data["prjId"]=$("#prjid").val();
	    			       data["payId"]=$("#payId").val();
	    			       data["payPd"]=$("#payPd1").val();
	    			     
	    			       data["transAm"]=$("#transAm").val();
	    			       data["transAccNoReturn"]=$("#transAccNoReturn").val();
	    			       data["transTm"]=$("#transTm").val();
	    			       data["transAcc"]=$("#transAcc").val();
	    			       data["transBank"]=$("#transBank").val();
	    			       data["insAccId"]=$("#insAccId").val();
	    			       
	    			       
	    			       
	    			        var url = '<%=path%>/rfbuss/fnovercollinfo/add.do';

	    			        var wait_dialog;
	    			        $.ajax({
	    			    		type: 'post',
	    			    		dataType:'json',
	    			    		data:data,
	    			    		url: url,
	    			    		beforeSend: function(){
	    					          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	    					     },
	    			    		success:function(msg){
	    			    			 wait_dialog.close();
	    			    			 if(msg.success == 1){
	    			    					 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
	    			    					 Remove_navTab();
	    						          	 //	$("#prjid").val(msg.data);
	    						          	   //cancelBtn();
	    						          	 	pageInApp.flag=false;
	    			    			 }else{
	    			    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    			    			 }
	    			    		}
	    			    	});
     	    	
	}
	//取消
	function cancelBtn(){
		  var TAB=top.mainApp.parentTab;
          var currentTabid=TAB.getSelectedTabItemID();
		 top.tab.removeTabItem(currentTabid);
	}

	//选择页面
	function choosePage(){
	
        $.ligerDialog.open({  title: '选择我司账户',height: 500,width: 850, url: '<%=path%>/rfbuss/fncprjbscinfo/toChooseCompAccPage.do?flag=ocr'});
	}
	//选择机构帐号
	function selectInsAcc(){
		 $.ligerDialog.open({  title: '选择机构账户',height: 500,width: 850, url: '<%=path%>/rfbase/fribaseinfo/toSearchBaListPage.do?fundRasInsId=${focvo.fncInsId}'});
	}
	
	  function initPayList(){
	   	   var instid = $("#fncInsId").val();
	   	
	   	  var combobox= $("#transAcc").ligerComboBox({
	             columns: [
	 		            /* { header: '账户类型', name: 'accTypNm', width: 100},  */
	 	                { header: '开户行名', name: 'bkNm', width: 100}, 
	 	                { header: '账户名称', name: 'accNm', width: 120},
	 	                { header: '账号', name: 'accNo', width: 120},
	 		            /* { header: '账户ID', name: 'id'}, */
	 	               ],
	 	            url:'<%=path%>/rfbase/fncprjfstpyinfo/initPayList.do?insId='+instid,
	 	            ajaxType :'GET',
	 	            width: 300, 
	 	            slide: false,
	 	            selectBoxWidth: 1880, 
	 	            selectBoxHeight: 740,
	 	            valueField: 'id', 
	 	            textField: 'accNo',
	 	           onSelected: function ()
	 	             {
	 	        	  var obj=combobox.getSelected();
	 	        	    $("#transBank").val(obj.bkNm);
	 	        	   
	 	             }
	 	       });
	   	liger.get("transAcc").selectValue("${focvo.transAcc}"); 
	     }
	  
	  
   /**  选择机构帐号，回调方法
	  *	 accNum 账号
	  * accNm 账户名称
	  * banAccNm 开户行
	  * banAccNum 开户行号
	  * id 主键
	  */
	  function setAccInfo(accNum,accNm,banAccNm,banAccNum,id){
		  
		  $("#insAccNum").val(accNum);
		  $("#insAccNm").html(accNm);
		  $("#insBanAccNm").html(banAccNm);
		  $("#insBanAccNum").html(banAccNum);
		  $("#insAccId").val(id);
	  }
		
		//自动计算当前盈余(当前盈余=退回金额+历史退回金额-已付超额抵押)
		function setSurplus(){
			var transAm = $("#transAm").val().replace(/[^\d\.-]/g, "");
			var hisTransAm = $("#hisTransAm").val();
			var paidUpAmt=new Number("${focvo.paidUpAmt/100}");
			var surplus = 0;
			$("#transAm").val(transAm);
			if(transAm!='' && hisTransAm!='' && paidUpAmt!=''){
				surplus = parseFloat(transAm) + parseFloat(hisTransAm) - parseFloat(paidUpAmt);
			}
			$("#surplus").val(surplus);
		}
    </script>

</body>
</html>